package org.liukai.tutorial.domain;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import javax.persistence.Transient;

import org.liukai.tutorial.utils.ConvertUtils;

import com.google.common.collect.Lists;

/**
 * 角色
 * 
 * @author liukai
 * 
 */
public class Role implements Serializable {

	private static final long serialVersionUID = -4406877364547252167L;

	private Integer id;

	private String name;

	private List<Authority> authorityList = Lists.newArrayList();

	Map<Integer, Integer> authCheckBox;

	/**
	 * 角色拥有的权限名称,多个权限用','分隔.
	 */
	@Transient
	public String getAuthNames() {
		return ConvertUtils.convertElementPropertyToString(authorityList,
				"name", ", ");
	}

	/**
	 * 角色拥有的权限ID字符串,多个权限ID用','分隔.
	 * 
	 * @return
	 */
	@Transient
	@SuppressWarnings("unchecked")
	public List<Integer> getAuthIds() {
		return ConvertUtils.convertElementPropertyToList(authorityList, "id");
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<Authority> getAuthorityList() {
		return authorityList;
	}

	public void setAuthorityList(List<Authority> authorityList) {
		this.authorityList = authorityList;
	}

	public Map<Integer, Integer> getAuthCheckBox() {
		return authCheckBox;
	}

	public void setAuthCheckBox(Map<Integer, Integer> authCheckBox) {
		this.authCheckBox = authCheckBox;
	}

}
